<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../plugins/layui/css/layui.css">
    <script type="text/javascript" src="../plugins/layui/layui.js"></script>

    <style type="text/css">
        body {
            background-image: url("./image/login_bg.jpg");
            background-repeat: no-repeat;
            background-size: cover;
        }
        .layui-card {
            position: absolute;
            width: 400px;
            right: 20%;
            top: 30%;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 2px 4px 6px #444;
        }

        .layui-form-label.title {
            font-size: 22px;
            color: #4E5465;
            margin-bottom: 20px;
            width: 100%;
            text-align: left
        }

        .layui-form-label.item {
            font-size: 16px;
            color: #4E5465;
        }
    </style>
</head>
<body>
<div class="layui-card">
    <label class="layui-form-label title">后青春的诗</label>
    <form action="login" method="post">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label item" style="width: 50px">账号</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入账号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label item" style="width: 50px">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 30px;">
            <div class="layui-input-block">
                <button class="layui-btn" onclick="doLogin()">登录</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use(['layer'], function () {
        $ = layui.jquery;
        layer = layui.layer;

        // 用户名控件获取焦点
        $('#username').focus();
        // 回车键提交
        $('input').onkeydown(function (e) {
            if (e.keyCode == 13) {
                doLogin();
            }
        });
    })

    // 登录
    function doLogin() {
        var userName = $.trim($('#username').val());
        var pwd = $.trim($('#password').val());
        $.post('/login', {'username': userName, 'pwd': pwd, 'verifyCode': verifyCode}, function (res) {
            // 登录回调
            layer.msg(res.msg)
            if (res.code == 0) {
                layer.msg(res.msg)
                setTimeout(function () {
                    window.location.href = '/admins.php/admins/Home/index'
                }, 1000)
            }
        }, 'json')
    }
</script>
</body>
</html>
